#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<string.h>

#define EventLength 1280*3 + 20 + 256 + 10


int main(int argc, char* argv[]){

  char* Path = argv[1];

  FILE* SiFile;
  SiFile = fopen(Path,"r");

  if(!SiFile){
    cout << "!!! ERROR !!!" << endl;
    cout << "File " << Path << " does not exist" << endl;
    return 0;
  }

  int ADC[2];

  //Run Header
  char Header[80];
  for(int i = 0; i < 5; i++){
    fgets(Header,80,SiFile); printf("%s",Header);
  }

  unsigned int tmp;
  
  for(int i = 0; i < EventLength; i++){
    
    if(feof(SiFile) || ferror(SiFile)) return 0;
    fread(&tmp,4,1,SiFile);

    if(i >= 4){

      if(tmp == 0xAABBCCDD){ 
	cout << "0xAABBCCDD" << endl;
	break;
      }

      //end of first telescope
      if(tmp == 0xAABBCC00){
	cout << " 0xAABBCC00 - Plane 1" << endl;
	continue;
      }

      //end of second telescope
      if(tmp == 0xAABBCC01){
	cout << " 0xAABBCC01 - Plane 2" << endl;
	continue;
      }

      //end of second telescope
      if(tmp == 0xAABBCC03){
	cout << " 0xAABBCC03 - Plane 3 " << endl;
	continue;
      }

      ADC[0] = (tmp >> 12)&0xfff;
      ADC[1] = (tmp & 0xfff);

      cout << ADC[0] << " " << ADC[1] << endl;

    }

  }

  return 0;

}//int main
